package xcmg.device.web.report;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import xcmg.device.infra.BasicController;
import xcmg.device.infra.DateUtil;
import xcmg.device.service.report.LackService;
import xcmg.device.service.vo.basic.MaterialsStorageVO;
import yb.ecp.fast.infra.annotation.FastMappingInfo;
import yb.ecp.fast.infra.infra.ActionResult;
import yb.ecp.fast.infra.infra.PageCommonVO;
import yb.ecp.fast.infra.infra.SearchCommonVO;
import yb.ecp.fast.infra.infra.log.LogHelper;

import java.util.Date;

@RestController
@RequestMapping("/report")
public class LackController extends BasicController {

    @Autowired
    private LackService lackService;

//    @Scheduled(cron = "0 0 */1 * * ?")
//    @SchedulerLock(name = "scheduledTaskName17", lockAtMostFor = 20*60*1000)
//    public void lack() throws Exception {
//        LogHelper.monitor("执行缺货到件提示任务："+ DateUtil.formatDateTime(new Date()));
//        lackService.saveLack();
//    }

//    /**
//     * 缺项分析报表定时任务
//     * @throws Exception
//     */
//    @Scheduled(cron = "0 59 23 * * ?")
//    @SchedulerLock(name = "scheduledTaskName22", lockAtMostFor = 14*60*1000, lockAtLeastFor = 14*60*1000)
//    public void missingAnalysisScheduled() throws Exception {
//        LogHelper.monitor("执行备件订单缺项分析提示任务："+ DateUtil.formatDateTime(new Date()));
//        lackService.missingAnalysisScheduled();
//    }

    @RequestMapping(value = "/missingAnalysisTest",method = RequestMethod.GET)
    @FastMappingInfo(needLogin = true)
    public void missingAnalysisTest() throws Exception {
        LogHelper.monitor("执行备件订单缺项分析提示任务："+ DateUtil.formatDateTime(new Date()));
        lackService.missingAnalysisScheduled();
    }


    @RequestMapping(value = "/inboundList",method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public ActionResult materialStorage(@RequestBody SearchCommonVO<MaterialsStorageVO> condition) throws Exception{
        MaterialsStorageVO materialsStorageVO=condition.getFilters();
        if(materialsStorageVO==null){
            materialsStorageVO=new MaterialsStorageVO();
        }
        materialsStorageVO.setOrgId(getOrgId());
        condition.setFilters(materialsStorageVO);
        PageCommonVO pageCommonVO = lackService.materialStorage(condition);
        return actionValueResult(pageCommonVO.getPageInfo());
    }

    @RequestMapping(value = "/inboundExportAll",method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public void exportAll(MaterialsStorageVO condition)throws Exception {
        condition.setOrgId(getOrgId());
        lackService.materialStorageExportAll(condition);
    }

    @RequestMapping(value = "/inboundTest",method = RequestMethod.POST)
    public void inboundTest(){
        LogHelper.monitor("执行缺货到件提示任务："+ DateUtil.formatDateTime(new Date()));
        lackService.saveLack();
    }
}
